<?php

namespace app\api\controller;

use app\admin\model\userstaff\UserClass;
use app\common\controller\Api;
use think\Config;
use think\Exception;

/**
 *  执法用户表
 */
class Staff extends Api
{
    protected $noNeedLogin = [];
    protected $noNeedRight = '*';

    protected $failException = true;

    public function _initialize()
    {
        parent::_initialize();
        $this->model = new \app\admin\model\userstaff\User();
        $this->modelClass = new UserClass();
        if (!Config::get('fastadmin.usercenter')) {
            $this->error(__('User center already closed'));
        }
    }

    /**
     * 用户列表
     */
    public  function list(){
        $input = input();
        $info = $this->auth->getUserinfo();
        try {
            $pageArr = [
                'page' => 1,
                'page_limit' => 30,
            ];

            $pageArr = array_merge($pageArr, $input);
            $where = [];
            if (!empty($input['type'])){
                $where['status'] = $input['type'];
            }
            $data = $this->model
                ->where('id' , '<>' , $info['staff_id'])
                ->where('user_staff_class_id', $info['user_staff_class_id'])
                ->where($where)
                ->order('id desc')
                ->paginate(['page' => $pageArr['page'] ?: 1, 'list_rows' => $pageArr['page_limit'] ?: 10]);
            $this->success('ok', $data);
        } catch (Exception $e) {
            $this->error($e->getMessage());
        }
    }




    /**
     * 上报用户列表
     */
    public  function task_list(){
        $input = input();
        $info = $this->auth->getUserinfo();
        try {
            if ($info['type'] != 1 && $info['type'] !=2){
                throw  new Exception('当前用户身份错误');
            }
            if($info['type'] == 1){
                $where['status'] = 2;
            }
            if($info['type'] == 2){
                $where['status'] = 3;
            }
            $pageArr = [
                'page' => 1,
                'page_limit' => 30,
            ];
            $pageArr = array_merge($pageArr, $input);
            $data = $this->model
                ->where('id' , '<>' , $info['staff_id'])
                ->where('user_staff_class_id', $info['user_staff_class_id'])
                ->where($where)
                ->order('id desc')
                ->paginate(['page' => $pageArr['page'] ?: 1, 'list_rows' => $pageArr['page_limit'] ?: 10]);
            $this->success('ok', $data);
        } catch (Exception $e) {
            $this->error($e->getMessage());
        }
    }

}